//
// Created by Aimeow on 2022/12/1.
//

import Foundation
import UIKit

class CheckSituationModel: NSObject {
    var situationValue: String = ""
    var checkValue: String = ""
    var uncheckValue: String = ""

    init(situationValue: String, checkValue: String, uncheckValue: String) {
        super.init()
        self.situationValue = situationValue
        self.checkValue = checkValue
        self.uncheckValue = uncheckValue
    }
}

class CheckSituationPanel: UIView {
    
    lazy var titleView: SectionTitleView = {
        let view = SectionTitleView(withStyle: SectionTitleStyleEnum.Style2, title: "签到完成情况")
        return view
    }()

    lazy var situationValueLabel: UILabel = {
        let label = UILabel()
        label.text = "0%"
        label.textColor = .hex("#3C72FF")
        label.font = UIFont.systemFont(ofSize: 30)
        return label
    }()

    lazy var checkTitleLabel: UILabel = {
        let label = UILabel()
        label.text = "签到"
        label.font = UIFont.systemFont(ofSize: 14)
        label.textColor = .hex("#999999")
        return label
    }()

    lazy var checkTitleValueLabel: UILabel = {
        let label = UILabel()
        label.text = "0"
        label.font = UIFont.systemFont(ofSize: 17)
        label.textColor = .hex("#010101")
        return label
    }()

    lazy var uncheckLabel: UILabel = {
        let label = UILabel()
        label.text = "签到异常"
        label.font = UIFont.systemFont(ofSize: 14)
        label.textColor = .hex("#999999")
        return label
    }()

    lazy var uncheckValueLabel: UILabel = {
        let label = UILabel()
        label.text = "0"
        label.font = UIFont.systemFont(ofSize: 17)
        label.textColor = .hex("#F17854")
        return label
    }()

    init() {
        super.init(frame: .zero)
        backgroundColor = UIColor.white
        setupUI()
    }

    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    func reload(withModal modal: SecurityBmQdWcQkModel?) {
        situationValueLabel.text = "\(modal?.qdwcl ?? 0)%"
        checkTitleValueLabel.text = "\(modal?.qds ?? 0)"
        uncheckValueLabel.text = "\(modal?.wqds ?? 0)"
    }
    
    func reload(withModal modal: BaglSecurityInfoQdwcModel?) {
        situationValueLabel.text = "\(modal?.qdwcl ?? "0")%"
        checkTitleValueLabel.text = "\(modal?.qds ?? 0)"
        uncheckValueLabel.text = "\(modal?.wqds ?? 0)"
    }

    func setupUI() {
        layer.masksToBounds = true
        layer.cornerRadius = 7

        addSubview(titleView)
        addSubview(situationValueLabel)
        addSubview(checkTitleLabel)
        addSubview(checkTitleValueLabel)
        addSubview(uncheckLabel)
        addSubview(uncheckValueLabel)

        titleView.snp.makeConstraints { make in
            make.left.equalToSuperview().offset(12)
            make.top.equalToSuperview().offset(16)
            make.height.equalTo(30)
        }
        
        let width = (ScreenWidth - 24.0) / 3.0

        situationValueLabel.snp.makeConstraints { make in
            make.left.equalToSuperview().offset(12)
            make.top.equalTo(titleView.snp.bottom).offset(15)
            make.width.equalTo(width)
        }

        checkTitleLabel.snp.makeConstraints { make in
            make.top.equalTo(situationValueLabel.snp.top)
            make.left.equalTo(situationValueLabel.snp.right)
            make.width.equalTo(width)
        }

        checkTitleValueLabel.snp.makeConstraints { make in
            make.left.equalTo(checkTitleLabel.snp.left)
            make.top.equalTo(checkTitleLabel.snp.bottom).offset(10)
            make.bottom.equalToSuperview().offset(-20)
        }

        uncheckLabel.snp.makeConstraints { make in
            make.left.equalTo(checkTitleLabel.snp.right)
            make.top.equalTo(checkTitleLabel)
            make.width.equalTo(width)
        }

        uncheckValueLabel.snp.makeConstraints { make in
            make.top.equalTo(checkTitleValueLabel)
            make.left.equalTo(uncheckLabel)
        }
    }

    func buildModel(model: CheckSituationModel) {
        situationValueLabel.text = model.situationValue
        checkTitleValueLabel.text = model.checkValue
        uncheckValueLabel.text = model.uncheckValue
    }
}
